<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var skydriveDataGrid;
    $(function() {
        skydriveDataGrid = $('#skydriveDataGrid').datagrid({
        url : '${path}/skydrive/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        singleSelect : true,
        idField : 'id',
        sortName : 'id',
        sortOrder : 'asc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [ {
            width : '140',
            title : '名称',
            field : 'fileName',
            sortable : true
        }, {
            width : '140',
            title : '创建人',
            field : 'userName',
            sortable : true
        }, {
            width : '140',
            title : '文件类型',
            field : 'isForder',
            sortable : true,
            formatter : function(value, row, index) {
                switch (value) {
                case 1:
                	 var str = '';
                	 str += $.formatString('<a href="javascript:void(0)" class="skydrive-easyui-linkbutton-foder" data-options="plain:true,iconCls:\'fi-folder icon-yellow\'" onclick="getFileFull(\'{0}\');" >文件夹</a>', row.sId);
                    return str;
                case 0:
                    return '<a href="javascript:void(0)" class="skydrive-easyui-linkbutton-file" data-options="plain:true,iconCls:\'fi-page-filled icon-yellow\'" ;" >文件</a>';
                }
            }
        },  {
            width : '140',
            title : '修改时时间',
            field : 'modifyTime',
            sortable : true
        }, {
            width : '140',
            title : '是否共享',
            field : 'isShare',
            sortable : true,
            formatter : function(value, row, index) {
                switch (value) {
                case 1:
                    return '是';
                case 0:
                    return '否';
                }
            }
        },{
            field : 'action',
            title : '操作',
            width : 200,
            formatter : function(value, row, index) {
                var str = '';
                <shiro:hasPermission name="/skydrive/download">
                    str += $.formatString('<a href="javascript:void(0)" class="skydrive-easyui-linkbutton-download" data-options="plain:true,iconCls:\'fi-download\'" onclick="skydriveDownloadFun(\'{0}\');" >下载</a>', row.sId);
                </shiro:hasPermission>
              /*   <shiro:hasPermission name="/skydrive/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="skydrive-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-page-edit\'" onclick="skydriveEditFun(\'{0}\');" >重命名</a>', row.sId);
                </shiro:hasPermission> */
                <shiro:hasPermission name="/skydrive/delete">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="skydrive-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="skydriveDeleteFun(\'{0}\');" >删除</a>', row.sId);
                </shiro:hasPermission>
                return str;
            }
        } ] ],
        onLoadSuccess:function(data){
        	$('.skydrive-easyui-linkbutton-file').linkbutton({text:'文件'});
        	$('.skydrive-easyui-linkbutton-foder').linkbutton({text:'文件夹'});
        	$('.skydrive-easyui-linkbutton-download').linkbutton({text:'下载'});
          //  $('.skydrive-easyui-linkbutton-edit').linkbutton({text:'重命名'});
            $('.skydrive-easyui-linkbutton-del').linkbutton({text:'删除'});
        },
        toolbar : '#skydriveToolbar'
    });
});

/**
*获得参数
**/
function getFileFull(id){  
	    $('.skydrive-easyui-linkbutton-foder').click(function(){
		$.ajax({
			type:'post',//类型
			url:'${pageContext.request.contextPath}/skydrive/getFileFull',//请求路径
			contentType: 'application/x-www-form-urlencoded',//默认
			dataType:'json',//返回数据类型  可以是text：字符串  可以是json：json对象
			data:{'id':id},//数据
			success:function(result){
				//alert("成功了");
				//alert(result.fileFullName);
				//var re = JSON.parse(result);
				//var re = JSON.stringify(result);
				//alert(re);
				var a = result.fileFullName;
				//$('#hidden1').value=result.sId;
				document.getElementById("hidden1").value=result.sId;
				$('#getFileFull').html("当前位置："+a);
				//alert("ID:"+$('#hidden1').value);
				var param = {"sId":result.sId};
				skydriveDataGrid.datagrid('reload',param);
			},
			error:function(data){//若果传过来的数据为空
				alert('亲，出错了');
			}
		});
	});
}

/**
*创建文件夹
**/
function addFile(){  
		parent.$.modalDialog({
            title : '新建文件夹',
            width : 500,
            height : 300,
            href : '${path }/skydrive/addPage',
            buttons : [ {
                text : '新建文件夹',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = skydriveDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#skydriveAddForm');
                    f.submit();
                }
            } ]
        });
}


/**
 * 上传
 * @param url
 */
function skydriveUpload() {
    parent.$.modalDialog({
        title : '上传',
        width : 400,
        height : 200,
        href : '${path}/skydrive/fileUploadPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = skydriveDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#skydriveUpload');
                f.submit();
            }
        } ]
    });
}

/**
 * 下载
 */
function skydriveDownloadFun(id) {
        document.getElementById("hidden2").value=id;
   		parent.$.modalDialog({
            title : '安全下载',
            width : 300,
            height : 100,
            href : '${path }/skydrive/downloadPage?id=' + id,
            buttons : [ {
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = skydriveDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#skydriveAddForm');
                    f.submit();
                }
            } ]
        });
}

/**
 * 删除
 */
 function skydriveDeleteFun(id) {
     parent.$.messager.confirm('询问', '您是否要删除文件(文件夹)', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/skydrive/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     skydriveDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}

/**
 * 重命名
 */
function skydriveEditFun(id) {
    if (id == undefined) {
        var rows = skydriveDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        skydriveDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : 700,
        height : 600,
        href :  '${path}/skydrive/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = skydriveDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#skydriveEditForm');
                f.submit();
            }
        } ]
    });
}



/**
 * 后退
 */
 function skydriveBack() {
 	 var sId = document.getElementById("hidden1").value;
 	 if(sId == 0){
 	 	alert("请不要挑战我的底线！");
 	 	sId = 304;
 	 }
 	 //alert(sId);
     $.ajax({
			type:'post',//类型
			url:'${pageContext.request.contextPath}/skydrive/back',//请求路径
			contentType: 'application/x-www-form-urlencoded',//默认
			dataType:'json',//返回数据类型  可以是text：字符串  可以是json：json对象
			data:{'sId':sId},//数据
			success:function(result){
				getFileFull(result.sId);
				var a = result.fileFullName;
				document.getElementById("hidden1").value=result.sId;
				$('#getFileFull').html("当前位置："+a);
				var param = {"sId":result.sId};
				skydriveDataGrid.datagrid('reload',param);
			},
			error:function(data){//若果传过来的数据为空
				alert('亲，出错了');
			}
		});
}

/**
 * 清除
 */
function skydriveCleanFun() {
    $('#skydriveSearchForm input').val('');
    skydriveDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function skydriveSearchFun() {
     skydriveDataGrid.datagrid('load', $.serializeObject($('#skydriveSearchForm')));
}
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
<!--     <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="skydriveSearchForm">
            <table>
                <tr>
                    <th>名称:</th>
                    <td><input name="name" placeholder="搜索条件"/></td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="skydriveSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="skydriveCleanFun();">清空</a>
                    </td>
                </tr>
            </table>
        </form>
     </div> -->
 
    <div data-options="region:'center',border:false">
        <table id="skydriveDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="skydriveToolbar" style="display: none;">
	<shiro:hasPermission name="/skydrive/add">
        <a onclick="skydriveUpload();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-upload'">上传</a>
    </shiro:hasPermission>
	<shiro:hasPermission name="/skydrive/createfolder">
        <a onclick="addFile();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-folder-add'">创建文件夹</a>
    </shiro:hasPermission>
	<shiro:hasPermission name="/skydrive/back">
        <a onclick="skydriveBack();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-arrow-left'">后退</a>
    </shiro:hasPermission>
    <div style="margin:7px;">
    	<font id="getFileFull"   style="color:#5F9EA0;font-size:16px;font-family:'Microsoft YaHei';">
    		全部文件
    	</font>
    </div>
    <input type="hidden" id="hidden1" value="">
    <input type="hidden" id="hidden2" value="">
</div>
